/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function(){
    $("#btnLogin").click(function(e) {
        e.preventDefault();
       if(validar("frmLogin"))
           $("#frmLogin").submit();
           
    });
})

function validar(formulario) {
    var ok = true;
    $("#" + formulario + " input").each(function(){
        if($(this).attr("data-required") === "required") {
            switch($(this).attr("type")) {
                case "text":
                case "password":
                case "tel":
                case "email":
                    if($(this).val() === "")  {
                        $("#" + $(this).attr("id") + "-erro").empty().append("<div class='message warning'>" +
                                      "<p>Por favor, preencha o campo " + $(this).attr("data-title") + "</p>" +
                                      "</div>");
                        ok = false;
                    }
                    break;
                case "checkbox":
                    if(!$(this).is(":checked")) {
                        $("#" + $(this).attr("id") + "-erro").empty().append("<div class='message warning'>" +
                                     "<p>Por favor, marque o campo " + $(this).attr("data-title") + "</p>" +
                                      "</div>");
                        ok = false;
                    
            }
        }
    }
    });
    
        $("#" + formulario + " select").each(function(){
            if($(this).attr("data-required") === "required" && $(this).val() === "") {
                $("#" + $(this).attr("id") + "-erro").empty().append("<div class='message warning'>" +
                                      "<i class='glyphicon glyphicon-exclamation-sign'></i>" +
                                      "<p>Por favor, informe o campo " + $(this).attr("data-title") + "</p>" +
                                      "</div>");
                ok = false;
            }   
        });
        
    $("#" + formulario + " textarea").each(function(){
        if($(this).attr("data-required") === "required" && $(this).val() === "") {
            $("#" + $(this).attr("id") + "-erro").empty().append("<div class='message warning'>" +
                                  "<i class='glyphicon glyphicon-exclamation-sign'></i>" +
                                  "<p>Por favor, preencha o campo " + $(this).attr("data-title") + "</p>" +
                                  "</div>");
            ok = false;
        }   
    });
    
    return ok;
}

